package com.construction.api.domain.model.result;

import com.construction.api.enums.ResultEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @author dybin
 * @Date: 2021/7/1 23:39
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class DataResult<T> extends BaseResult {

    private T data;

    public DataResult(Integer code, String msg, T data) {
        super(code, msg);
        this.data = data;
    }

    public static <T> DataResult<T> of(Integer code, String msg, T data) {
        return new DataResult<>(code, msg, data);
    }

    public static <T> DataResult<T> of(ResultEnum resultEnum, T data) {
        return DataResult.of(resultEnum.getCode(), resultEnum.getMsg(), data);
    }

    public static <T> DataResult<T> success(T data) {
        return DataResult.of(ResultEnum.SUCCESS, data);
    }

}
